import { createStore, applyMiddleware } from 'redux'
import thunk from 'redux-thunk'
import { composeWithDevTools } from '@redux-devtools/extension'
import rootReducer from './reducer/index'
import storage from 'redux-persist/lib/storage'

import { persistReducer, persistStore } from 'redux-persist'

// 定义持久化配置
const persistConfig = {
  key: 'root',
  storage
  // blacklist:['loading']  //设置某个reducer数据不持久化
}
const persistedReducer = persistReducer(persistConfig, rootReducer)
// 创建仓库时，我们必须传递reducer，其它参数是可选的
const store = createStore(
  persistedReducer,
  composeWithDevTools(applyMiddleware(thunk))
)

const persistor = persistStore(store)
// export default store
export { store, persistor }

export type RootState = ReturnType<typeof store.getState>
export type AppDispatch = typeof store.dispatch
